#!/bin/bash
docker pull mysql
mkdir /opt  >/dev/null
mkdir /opt/mysql
mkdir /opt/mysql/conf/
mkdir /opt/mysql/conf/conf.d
mkdir /opt/mysql/logs/
mkdir /opt/mysql/data/
echo "[mysqld]
user=mysql
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
 
[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4" > /opt/mysql/my.cnf

docker run --restart=always --privileged=true  \
-v /opt/mysql/data/:/var/lib/mysql \
-v /opt/mysql/logs/:/var/log/mysql \
-v /opt/mysql/conf/:/etc/mysql \
-v /opt/mysql/my.cnf:/etc/mysql/my.cnf  \
-p 3306:3306 --name my-mysql \
-e MYSQL_ROOT_PASSWORD=123456 -d mysql


# in sql config
# use mysql;
#grant all privileges on *.* to 'root'@'%';
#flush privileges;